package com.sugar.psych.assessment.module.business.service.basicconfig;

import cn.hutool.core.collection.CollUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import com.sugar.psych.assessment.module.business.controller.admin.basicconfig.vo.*;
import com.sugar.psych.assessment.module.business.dal.dataobject.basicconfig.BasicConfigDO;
import com.sugar.psych.assessment.framework.common.pojo.PageResult;
import com.sugar.psych.assessment.framework.common.pojo.PageParam;
import com.sugar.psych.assessment.framework.common.util.object.BeanUtils;

import com.sugar.psych.assessment.module.business.dal.mysql.basicconfig.BasicConfigMapper;

import static com.sugar.psych.assessment.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.sugar.psych.assessment.framework.common.util.collection.CollectionUtils.convertList;
import static com.sugar.psych.assessment.framework.common.util.collection.CollectionUtils.diffList;
import static com.sugar.psych.assessment.module.business.enums.ErrorCodeConstants.*;

/**
 * 基本配置 Service 实现类
 *
 * @author Ysugar
 */
@Service
@Validated
public class BasicConfigServiceImpl implements BasicConfigService {

    @Resource
    private BasicConfigMapper basicConfigMapper;

    @Override
    public void createBasicConfig(BasicConfigSaveReqVO createReqVO) {
        BasicConfigDO basicConfig = BeanUtils.toBean(createReqVO, BasicConfigDO.class);
        basicConfig.setId(1L);

        if (Objects.isNull(basicConfigMapper.selectById(1)))
            basicConfigMapper.insert(basicConfig);
        else
            basicConfigMapper.updateById(basicConfig);
    }


    @Override
    public BasicConfigDO getBasicConfig(Long id) {
        BasicConfigDO config = basicConfigMapper.selectById(id);
        if (Objects.isNull(config)){
            config = new BasicConfigDO();
            config.setUserAgreement("");
            config.setAssessmentRisk("");
            config.setUserDefaultAvatar("");
            config.setCenterHotline("");
        }

        return config;
    }


}